package com.woniu.gym.controller;


import com.woniu.core.util.JwtUtil;
import com.woniu.core.util.PageInfo;
import com.woniu.core.util.RedisUtil;
import com.woniu.core.util.Result;
import com.woniu.gym.dao.TGymCoachInfoMapper;
import com.woniu.gym.dto.GymFindCoachInfoDto;
import com.woniu.gym.dto.GymJobCoachInfoDto;
import com.woniu.gym.dto.MyFansDto;
import com.woniu.gym.dto.UserFindCoachInfoDto;
import com.woniu.gym.form.GymFindCoachInfoForm;
import com.woniu.gym.form.ModifyGymCoachInfoForm;
import com.woniu.gym.form.UserFindCoachInfoForm;
import com.woniu.gym.model.TGymCoachInfo;
import com.woniu.gym.service.TGymCoachInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 吴彦祖
 * @since 2024年04月02日
 */
@RestController
@RequestMapping("/tGymCoachInfo")
@Api(tags = "场馆签约的教练管理接口")
public class TGymCoachInfoController {
    @Resource
    private TGymCoachInfoService tGymCoachInfoService;
    @Resource
    private RedisUtil redisUtil;
    @ApiOperation("查询在职的无课的教练（团课）")
    @GetMapping("/commentCoach.gym")
    public Result<List<GymJobCoachInfoDto>> commentCoch(String gymNum){
        List<GymJobCoachInfoDto> list = tGymCoachInfoService.commentCoch(gymNum);
        return Result.getListResult(GymJobCoachInfoDto.class).setMsg("查询成功").setData(list);
    }

    @ApiOperation("查询在职的无课的教练（私课）")
    @GetMapping("/underCoach.gym")
    public Result<List<GymJobCoachInfoDto>> underCoch(String gymNum){
        List<GymJobCoachInfoDto> list = tGymCoachInfoService.underCoch(gymNum);
        return Result.getListResult(GymJobCoachInfoDto.class).setMsg("查询成功").setData(list);
    }
    @ApiOperation("用户分页查询所有场馆在职的的教练")
    @GetMapping("/userFindAllCoach.user")
    public Result userFindAllCoach(UserFindCoachInfoForm form){
        PageInfo<UserFindCoachInfoDto> list = tGymCoachInfoService.userFindAllCoach(form);
        return Result.getResult(PageInfo.class).setMsg("查询成功").setData(list);
    }
    @ApiOperation("场馆查询自己的签约教练")
    @GetMapping("/gymFindAllCoach.gym")
    public Result gymFindAllCoach(GymFindCoachInfoForm form){
        PageInfo<GymFindCoachInfoDto> list = tGymCoachInfoService.gymFindAllCoach(form);
        return Result.getResult(PageInfo.class).setMsg("查询成功").setData(list);
    }
    @ApiOperation("课程结束后根据教练id修改为0无课状态")
    @GetMapping("/modifyCoachNoWork/{coachId}")
    public Result<TGymCoachInfo> modifyCoachNoWork(@PathVariable ("coachId") Integer coachId){
        TGymCoachInfo gymCoachInfo = tGymCoachInfoService.modifyCoachNoWork(coachId);
        return Result.getResult(TGymCoachInfo.class).setMsg("修改成功").setData(gymCoachInfo);
    }
    @ApiOperation("排课后根据教练id修改为1有课状态")
    @GetMapping("/modifyCoachHaveWork/{coachId}")
    public Result<TGymCoachInfo> modifyCoachHaveWork(@PathVariable ("coachId") Integer coachId){
        TGymCoachInfo gymCoachInfo = tGymCoachInfoService.modifyCoachHaveWork(coachId);
        return Result.getResult(TGymCoachInfo.class).setMsg("修改成功").setData(gymCoachInfo);
    }
    @ApiOperation("用户评价后根据教练id修改教练评分")
    @GetMapping("/modifyCoachMark/{coachId}/{coachMark}")
    public Result<TGymCoachInfo> modifyCoachMark(@PathVariable ("coachId") Integer coachId,@PathVariable ("coachMark") Double coachMark){
        TGymCoachInfo gymCoachInfo = tGymCoachInfoService.modifyCoachMark(coachId,coachMark);
        return Result.getResult(TGymCoachInfo.class).setMsg("修改成功").setData(gymCoachInfo);
    }

    @ApiOperation("修改基本信息（包含修改离职（解约）状态）")
    @PostMapping("/modifyInformation.gym")
    public Result<TGymCoachInfo> modifyInformation(@RequestBody @Valid ModifyGymCoachInfoForm form){
        TGymCoachInfo gymCoachInfo = tGymCoachInfoService.modifyInformation(form);
        return Result.getResult(TGymCoachInfo.class).setMsg("修改成功").setData(gymCoachInfo);
    }

    @ApiOperation("用户关注教练（场馆）")
    @GetMapping("/follow")
    public Result<GymFindCoachInfoDto> follow(Integer coachId,@RequestHeader String token)throws Exception{
        String refreshToken = redisUtil.get(token);
        Integer userId =Integer.parseInt( JwtUtil.parseToken(refreshToken,2).get("id").toString());
        GymFindCoachInfoDto dto = tGymCoachInfoService.follow(coachId,userId);
        return Result.getResult(GymFindCoachInfoDto.class).setMsg("关注/取消关注成功").setData(dto);
    }
    @ApiOperation("场馆查询自己的粉丝列表")
    @GetMapping("/myFans.coach")
    public Result myFans(Integer pageNum,Integer pageSize,Integer coachInfoId) throws Exception {
        PageInfo<MyFansDto> dto = tGymCoachInfoService.myFans(pageNum,pageSize,coachInfoId);
        return Result.getResult(PageInfo.class).setMsg("查询成功").setData(dto);
    }

}

